﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using unitlControl;
namespace QuanLy_THPT_S4
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }
        public Dictionary<Type, Form> OpenForm = new Dictionary<Type, Form>();

        /// <summary>
        /// Đống tấc cả các from đang mở
        /// </summary>
        private void CloseAll_tap()
        {
            foreach (var item in MdiChildren)
            {
                item.Close();
            }
        }

        /// <summary>
        /// Kiểm soát đống mở from
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="_kiemtra"></param>
        private void ShowForm<T>(bool _kiemtra = true) where T : Form, new()
        {
            Form frm;
            OpenForm.TryGetValue(typeof(T), out frm);
            if (frm == null || frm.IsDisposed)
            {
                if (_kiemtra)
                {
                    CloseAll_tap();
                }
                frm = new T();
                OpenForm[typeof(T)] = frm;
                frm.MdiParent = this;
                frm.Show();

            }
            else
            {
                frm.Activate();
            }

        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmGiaoVien>();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmNamHoc>();
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmDSLop>();
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<HocSinh.frmHocSinh>();
        }

        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<GiaoVien.frmNhapDiem>();
        }

        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TienIch.frmQLNguoiDung frm = new TienIch.frmQLNguoiDung();
            DialogResult rs = frm.ShowDialog();
            if (rs == DialogResult.Cancel)
            { 
            
            }

        }

        private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmPhanLopHS>();
        }

        private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmGVCN frm = new frmGVCN();
            DialogResult rs = frm.ShowDialog();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //Kiểm tra đăng nhập
            frmDangNhap frm = new frmDangNhap();
            this.Enabled = false;
            DialogResult rs = frm.ShowDialog();
            if (rs == DialogResult.Cancel)
            {
                if (frm.Ktdn)
                {
                    try
                    {
                        barTenND.Caption = toancuc.ThongtinND.Gv.Holot + ' ' + toancuc.ThongtinND.Gv.Ten;
                        barQuyenDN.Caption = toancuc.ThongtinND.Pq.Tenpq;
                        this.Enabled = true;
                    }
                    catch { }
                }
                else
                {
                    Application.Exit();
                }
              
                
            }
        }

        private void barButtonItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TienIch.frmDoiMK frm = new TienIch.frmDoiMK();
            DialogResult rs = frm.ShowDialog();
            if (rs == DialogResult.Cancel)
            {
                frm.Dispose();
            }
        }

        private void barButtonItem10_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barTenND.Caption = "";
            barQuyenDN.Caption = "";
            frmMain_Load(sender, e);
        
        }

        private void ribbonControl1_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItem12_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<frmMonHoc>();
        }

        private void barButtonItem16_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<Danh_sách.frmToChuyenMon>();
        }

        private void barButtonItem11_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TKB.frmTKB frm = new TKB.frmTKB();
            DialogResult rs = frm.ShowDialog();
        }

        private void barButtonItem17_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void barButtonItem14_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<DanhSach.frmDienUuTien>();
        }

        private void barButtonItem18_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<GiaoVien.frmNhapHanhKiem>();
        }

        private void barButtonItem31_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThiCu.frmThiSinhViPhamQuyChe>();
        }

        private void barButtonItem15_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThiCu.frmDSPhongThi>();
        }

        private void barButtonItem20_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThiCu.frmDsThiSinh>();
        }

        private void barButtonItem30_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThiCu.frmDSGiamThi>();
        }

        private void barButtonItem33_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThongKe.frmDiemLopTheoMon>();
        }

        private void barButtonItem32_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThongKe.frmDiemTheoLop>();
        }

        private void barButtonItem34_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowForm<ThongKe.frmDiemHSTheoMon>();
        }

        private void barButtonItem27_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            TienIch.frmThongTinNguoiDung frm = new TienIch.frmThongTinNguoiDung();
            DialogResult rs = frm.ShowDialog();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            barTime.Caption = DateTime.Now.ToString("dd-MM-yyyy mm:ss");
        }

       
    }
}
